<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-PBHRK7');</script>
<!-- End Google Tag Manager -->
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="flutter," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.2" />






<meta name="description" content="前言上一篇，我们刚完成了启动页，这一篇我们来进行一下简单的首页配置以及页面配置吧 改造一下首页吧lib/pages/boot_page.dart  我们编写一个有点击效果的按钮 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960">
<meta name="keywords" content="flutter">
<meta property="og:type" content="article">
<meta property="og:title" content="Flutter实践 -- 编写目录首页与路由配置">
<meta property="og:url" content="http://wurh.github.io/2019/11/06/201911061709/index.html">
<meta property="og:site_name" content="华Ing&#39;s blog">
<meta property="og:description" content="前言上一篇，我们刚完成了启动页，这一篇我们来进行一下简单的首页配置以及页面配置吧 改造一下首页吧lib/pages/boot_page.dart  我们编写一个有点击效果的按钮 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960">
<meta property="og:locale" content="en">
<meta property="og:image" content="https://wurh.github.io/images/blogs/shijian04/shijian04-1.png">
<meta property="og:image" content="https://wurh.github.io/images/blogs/shijian04/shijian04-2.png">
<meta property="og:updated_time" content="2019-11-06T09:14:45.738Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Flutter实践 -- 编写目录首页与路由配置">
<meta name="twitter:description" content="前言上一篇，我们刚完成了启动页，这一篇我们来进行一下简单的首页配置以及页面配置吧 改造一下首页吧lib/pages/boot_page.dart  我们编写一个有点击效果的按钮 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960">
<meta name="twitter:image" content="https://wurh.github.io/images/blogs/shijian04/shijian04-1.png">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: 'Author'
    }
  };
</script>




  <link rel="canonical" href="http://wurh.github.io/2019/11/06/201911061709/"/>


  <title> Flutter实践 -- 编写目录首页与路由配置 | 华Ing's blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PBHRK7"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

  










  
  
    
  

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-69412379-1', 'auto');
  ga('send', 'pageview');

</script>

  <script>
  var _hmt = _hmt || [];
  (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b3ddfb8655d8b77429e04c7a4d5bcbc1";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
  </script>


  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">华Ing's blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">harder and harder</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Flutter实践 -- 编写目录首页与路由配置
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2019-11-06T17:09:00+08:00" content="2019-11-06">
              2019-11-06
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Flutter实践/" itemprop="url" rel="index">
                    <span itemprop="name">Flutter实践</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2019/11/06/201911061709/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2019/11/06/201911061709/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>上一篇，我们刚完成了启动页，这一篇我们来进行一下简单的首页配置以及页面配置吧</p>
<h3 id="改造一下首页吧"><a href="#改造一下首页吧" class="headerlink" title="改造一下首页吧"></a>改造一下首页吧</h3><p>lib/pages/boot_page.dart  我们编写一个有点击效果的按钮</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">BootPage</span> <span class="keyword">extends</span> <span class="title">StatefulWidget</span> </span>&#123;</span><br><span class="line">  <span class="meta">@override</span></span><br><span class="line">  _BootPageState createState() =&gt; _BootPageState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">_BootPageState</span> <span class="keyword">extends</span> <span class="title">State</span>&lt;<span class="title">BootPage</span>&gt; </span>&#123;</span><br><span class="line">  <span class="meta">@override</span></span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    <span class="keyword">return</span> Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(<span class="string">'Home Page'</span>),</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        alignment: Alignment.center,</span><br><span class="line">        child: GridView.count(</span><br><span class="line">          primary: <span class="keyword">false</span>,</span><br><span class="line">          padding: <span class="keyword">const</span> EdgeInsets.all(<span class="number">20</span>),</span><br><span class="line">          crossAxisSpacing: <span class="number">10</span>,</span><br><span class="line">          mainAxisSpacing: <span class="number">10</span>,</span><br><span class="line">          crossAxisCount: <span class="number">2</span>,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            Ink(</span><br><span class="line">              <span class="comment">//设置背景</span></span><br><span class="line">              decoration: <span class="keyword">new</span> BoxDecoration(</span><br><span class="line">                <span class="comment">//背景</span></span><br><span class="line">                color: Colors.blue[<span class="number">200</span>],</span><br><span class="line">                <span class="comment">//设置四周圆角 角度</span></span><br><span class="line">                borderRadius: BorderRadius.all(Radius.circular(<span class="number">25.0</span>)),</span><br><span class="line">              ),</span><br><span class="line">              child: <span class="keyword">new</span> InkResponse(</span><br><span class="line">                borderRadius: <span class="keyword">new</span> BorderRadius.all(<span class="keyword">new</span> Radius.circular(<span class="number">25.0</span>)),</span><br><span class="line">                <span class="comment">//点击或者toch控件高亮时显示的控件在控件上层,水波纹下层</span></span><br><span class="line">                <span class="comment">//    highlightColor: Colors.deepPurple,</span></span><br><span class="line">                <span class="comment">//点击或者toch控件高亮的shape形状</span></span><br><span class="line">                <span class="comment">//  highlightShape: BoxShape.rectangle,</span></span><br><span class="line">                <span class="comment">//.InkResponse内部的radius这个需要注意的是，我们需要半径大于控件的宽，如果radius过小，显示的水波纹就是一个很小的圆，</span></span><br><span class="line">                <span class="comment">//水波纹的半径</span></span><br><span class="line">                radius: <span class="number">300.0</span>,</span><br><span class="line">                <span class="comment">//水波纹的颜色</span></span><br><span class="line">                splashColor: Colors.yellow,</span><br><span class="line">                <span class="comment">//true表示要剪裁水波纹响应的界面 false不剪裁 如果控件是圆角不剪裁的话水波纹是矩形</span></span><br><span class="line">                containedInkWell: <span class="keyword">true</span>,</span><br><span class="line">                <span class="comment">//点击事件</span></span><br><span class="line">                onTap: () <span class="keyword">async</span> &#123;</span><br><span class="line">                  <span class="built_in">print</span>(<span class="string">"click"</span>);</span><br><span class="line">                  <span class="comment">// await new Future.delayed(new Duration(milliseconds: 1000));</span></span><br><span class="line">                  <span class="comment">// Application.router.navigateTo(context, '/');</span></span><br><span class="line">                &#125;,</span><br><span class="line">                child: Container(</span><br><span class="line">                  <span class="comment">//设置 child 居中</span></span><br><span class="line">                  alignment: Alignment(<span class="number">0</span>, <span class="number">0</span>),</span><br><span class="line">                  height: <span class="number">50</span>,</span><br><span class="line">                  width: <span class="number">300</span>,</span><br><span class="line">                  child: Text(</span><br><span class="line">                    <span class="string">'Demo1'</span>,</span><br><span class="line">                    style: TextStyle(color: Colors.white),</span><br><span class="line">                  ),</span><br><span class="line">                ),</span><br><span class="line">              ),</span><br><span class="line">            ),</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>接着我们可以看到效果如下:</p>
<p><img src="https://wurh.github.io/images/blogs/shijian04/shijian04-1.png" alt="alt"></p>
<h3 id="为fluter增加路由跳转"><a href="#为fluter增加路由跳转" class="headerlink" title="为fluter增加路由跳转"></a>为fluter增加路由跳转</h3><h4 id="原生-Navigator-跳转"><a href="#原生-Navigator-跳转" class="headerlink" title="原生 Navigator 跳转"></a>原生 Navigator 跳转</h4><p>在上一节中，我们在lib/main.dart 中是已经配置过路由地址了， 代码如下</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">return</span> MaterialApp(</span><br><span class="line">  debugShowCheckedModeBanner: <span class="keyword">false</span>,</span><br><span class="line">  home: SplashPage(),</span><br><span class="line">  routes: &#123;</span><br><span class="line">    <span class="string">'/BootPage'</span>: (ctx)=&gt; BootPage()</span><br><span class="line">  &#125;,</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line">...</span><br><span class="line"></span><br><span class="line">Navigator.of(context).pushReplacementNamed(<span class="string">"/BootPage"</span>);</span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<h4 id="使用flutter-插件-fluro-进行路由配置"><a href="#使用flutter-插件-fluro-进行路由配置" class="headerlink" title="使用flutter 插件 fluro 进行路由配置"></a>使用flutter 插件 <code>fluro</code> 进行路由配置</h4><p>访问<a href="https://pub.dev/" title="pub.dev" target="_blank" rel="noopener">Flutter 仓库</a> 搜索fluro</p>
<p>接着我们在 <code>pubspec.yaml</code> 加上如下代码</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fluro: ^<span class="number">1.5</span><span class="number">.1</span></span><br></pre></td></tr></table></figure>
<p>我们再调整一下首页 lib/main.dart</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter_myapp/pages/boot_page.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter_myapp/pages/splash_page.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:fluro/fluro.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter_myapp/routers/application.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter_myapp/routers/routes.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//页面调试标尺</span></span><br><span class="line"><span class="comment">// import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">void</span> main() =&gt; runApp(MyApp());</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MyApp</span> <span class="keyword">extends</span> <span class="title">StatelessWidget</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">  <span class="meta">@override</span></span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">final</span> router = Router();</span><br><span class="line">    Routes.configureRoutes(router);</span><br><span class="line">    Application.router=router;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> MaterialApp(</span><br><span class="line">      debugShowCheckedModeBanner: <span class="keyword">false</span>,</span><br><span class="line">      home: SplashPage(),</span><br><span class="line">      routes: &#123;</span><br><span class="line">        <span class="string">'/BootPage'</span>: (ctx)=&gt; BootPage()</span><br><span class="line">      &#125;,</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>创建 lib/pages/demo/demo1_page.dart</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Demo1Page</span> <span class="keyword">extends</span> <span class="title">StatefulWidget</span> </span>&#123;</span><br><span class="line">  <span class="meta">@override</span></span><br><span class="line">  _Demo1PageState createState() =&gt; _Demo1PageState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">_Demo1PageState</span> <span class="keyword">extends</span> <span class="title">State</span>&lt;<span class="title">Demo1Page</span>&gt; </span>&#123;</span><br><span class="line">  <span class="meta">@override</span></span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    <span class="keyword">return</span> Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(<span class="string">'Demo1'</span>),</span><br><span class="line">      ),</span><br><span class="line">      body: Text(<span class="string">'我是Demo1 Page'</span>),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>创建 lib/routers/application.dart</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:fluro/fluro.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Application</span></span>&#123;</span><br><span class="line">  <span class="keyword">static</span> Router router;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>创建 lib/routers/router_handler.dart</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:fluro/fluro.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter_myapp/pages/demo/demo1_page.dart'</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Handler demo1Handler =Handler(</span><br><span class="line">  handlerFunc: (BuildContext context,<span class="built_in">Map</span>&lt;<span class="built_in">String</span>,<span class="built_in">List</span>&lt;<span class="built_in">String</span>&gt;&gt; params)&#123;</span><br><span class="line">     <span class="keyword">return</span> Demo1Page();</span><br><span class="line">  &#125;</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<p>创建 lib/routers/routes.dart</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'./router_handler.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:fluro/fluro.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Routes</span></span>&#123;</span><br><span class="line">  <span class="keyword">static</span> <span class="built_in">String</span> root=<span class="string">'/'</span>;</span><br><span class="line">  <span class="keyword">static</span> <span class="built_in">String</span> demo1Page = <span class="string">'/demo1'</span>;</span><br><span class="line">  <span class="keyword">static</span> <span class="keyword">void</span> configureRoutes(Router router)&#123;</span><br><span class="line">    router.notFoundHandler= <span class="keyword">new</span> Handler(</span><br><span class="line">      handlerFunc: (BuildContext context,<span class="built_in">Map</span>&lt;<span class="built_in">String</span>,<span class="built_in">List</span>&lt;<span class="built_in">String</span>&gt;&gt; params)&#123;</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">'ERROR====&gt;ROUTE WAS NOT FONUND!!!'</span>);</span><br><span class="line">      &#125;</span><br><span class="line">    );</span><br><span class="line"></span><br><span class="line">    router.define(demo1Page,handler:demo1Handler);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>最后我们只要在demo的按钮增加地址的跳转则可以了！  lib/pages/boot_page.dart</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"> onTap: () <span class="keyword">async</span> &#123;</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">"click"</span>);</span><br><span class="line">  <span class="comment">// await new Future.delayed(new Duration(milliseconds: 1000));</span></span><br><span class="line">  Application.router.navigateTo(context, <span class="string">'/demo1'</span>);</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>
<p>我们可以来看看效果了</p>
<p><img src="https://wurh.github.io/images/blogs/shijian04/shijian04-2.png" alt="alt"></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="https://wurh.github.io/images/others/weixinshou.png" alt="华Ing WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="https://wurh.github.io/images/others/alifu.png" alt="华Ing Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/flutter/" rel="tag">#flutter</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/11/05/201911052016/" rel="next" title="Flutter实践 -- 启动页">
                <i class="fa fa-chevron-left"></i> Flutter实践 -- 启动页
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/11/12/201911121536/" rel="prev" title="Flutter实践 -- 按钮组件">
                Flutter实践 -- 按钮组件 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        
<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2019/11/06/201911061709/"
           data-title="Flutter实践 -- 编写目录首页与路由配置" data-url="http://wurh.github.io/2019/11/06/201911061709/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="https://wurh.github.io/images/avatar/logo.jpg?123456"
               alt="华Ing" />
          <p class="site-author-name" itemprop="name">华Ing</p>
          <p class="site-description motion-element" itemprop="description">harder and harder</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">56</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">11</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/wurh" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/1674582564/profile?topnav=1&wvr=6" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/wu-rong-hua-56" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://fsiaonma.github.io/" title="sam博客" target="_blank">sam博客</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://shenjoel.github.io/" title="joel博客" target="_blank">joel博客</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://firewood1122.github.io" title="firewood博客" target="_blank">firewood博客</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://reqianduan.com" title="热前端" target="_blank">热前端</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://opentutorial.info/" title="黄超博客" target="_blank">黄超博客</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#改造一下首页吧"><span class="nav-number">2.</span> <span class="nav-text">改造一下首页吧</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#为fluter增加路由跳转"><span class="nav-number">3.</span> <span class="nav-text">为fluter增加路由跳转</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#原生-Navigator-跳转"><span class="nav-number">3.1.</span> <span class="nav-text">原生 Navigator 跳转</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用flutter-插件-fluro-进行路由配置"><span class="nav-number">3.2.</span> <span class="nav-text">使用flutter 插件 fluro 进行路由配置</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2013 - 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">华Ing</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.2"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"wurh"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  

  


</body>
</html>
